<template>
  <view>
    <ji-gif v-if="is_ji_gif"></ji-gif>
    <!-- 通知 -->
    <view v-if="donghua.message_list[0]" class="message">
      <image :src="message_list[message_index].avatar"></image>
      <text>{{ message_list[message_index].content }}</text>
    </view>
    <!-- 背包鸡蛋 -->
    <view class="beibao">
      <view class="img">
        <image :src="user_info.avatar"></image>
      </view>
      <view class="beijing">
        <view class="jidan-yiyou">{{ ji_info.chicken_info.eggs }}</view>
        <view class="lingqu">换鸡蛋</view>
      </view>
    </view>
    <!-- 攻略 -->
    <view class="gonluen" v-if="0">
      <view class="img">
        <image src="https://wechat-pictures-1301970825.file.myqcloud.com/yangji/攻略.png"></image>
      </view>
      <view class="gonluen-msg">攻略</view>
    </view>
    <!-- 好友 -->
    <view class="haoyou" @click="get_user_list">
      <view class="img">
        <image src="https://wechat-pictures-1301970825.file.myqcloud.com/yangji/huijia.png"></image>
      </view>
      <view class="gonluen-msg">回家</view>
    </view>
    <!-- 饲料 -->
    <view @click="show_renwu" class="haoyou siliao" v-if="0">
      <view class="img">
        <image src="https://wechat-pictures-1301970825.file.myqcloud.com/yangji/领饲料.png"></image>
      </view>
      <view class="gonluen-msg">饲料</view>
    </view>
    <!-- 喂饲料 -->
    <view @click="weisiliao" class=" wei-siliao" v-if="0">
      <ar-circle-progress borderWidth="10" activeColor="#fbac37" width="120" :percent="percent">
        <view class="siliao-img">
          <image mode="widthFix" src="https://wechat-pictures-1301970825.file.myqcloud.com/yangji/有食物盆.png"></image>
          <view class="gonluen-msg">喂饲料</view>
        </view>
      </ar-circle-progress>
    </view>
    <!-- 饭盆 -->
    <view :class="donghua.fanpen?'fanpen fanpen-donghua':'fanpen'" v-if="ji_info.jinshi_info.is_over==1">
      <image mode="widthFix" src="https://wechat-pictures-1301970825.file.myqcloud.com/yangji/kongpen.png"></image>
    </view>
    <!-- 泡泡 -->
    <view class="paopao">
      <view class="xingqing-text">心情</view>
      <image mode="widthFix" src="https://wechat-pictures-1301970825.file.myqcloud.com/yangji/xinping.png"></image>
      <view class="paopao-msg">{{ ji_info.chicken_info.emotion_value }}</view>
    </view>
    <view class="baj">
      <!-- 眨眼小鸡 -->
      <view v-if="ji_info.jinshi_info.is_over==1" @click="set_motou" class="moutou ji">
        <!-- 话术 -->
        <view v-if="donghua.message" class="hua-message">
          {{ t_message }}
        </view>
      </view>
      <!-- 吃饭小鸡 -->
      <view @click="set_motou" v-if="ji_info.jinshi_info.is_over==0" class="chishi-ji ji">
        <!-- 话术 -->
        <view v-if="donghua.message" class="hua-message">
          {{ t_message }}
        </view>
      </view>
      <!-- 鸡粑粑 -->
      <view v-if="user_info.is_help==0" @click="del_ji_baba()" :class="donghua.baba?'jibaba jibaba-donghua':'jibaba'">
        <image src="https://wechat-pictures-1301970825.file.myqcloud.com/yangji/bianbian.png"></image>
      </view>
      <!-- 正在下的鸡蛋 -->
      <view @click="jiwu" class="jiwu">
        <image class="jidan" src="https://wechat-pictures-1301970825.file.myqcloud.com/yangji/jidian.png"></image>
        <image class="jiwu-img" src="https://wechat-pictures-1301970825.file.myqcloud.com/yangji/jiwo.png"></image>
        <view class="jindutiao">
          <view class="jindu" :style="'width:'+ji_info.chicken_info.grow_value+'%'"></view>
          <view class="msg">{{ ji_info.chicken_info.grow_value }}%</view>
        </view>
      </view>
      <!-- 正在吃饭的鸡 -->
      <view v-if="ji_info.jinshi_info.is_over==0" class="chi-fan">
        <image mode="widthFix" class="chi-fanpen"
               src="https://wechat-pictures-1301970825.file.myqcloud.com/yangji/yousiliaofanpen.png">
        </image>
        <view class="jindu">
          {{ ji_info.jinshi_info.end_time_shifen }}
          <image src="https://wechat-pictures-1301970825.file.myqcloud.com/yangji/时间.png"></image>
        </view>
      </view>

    </view>
    <!-- 任务 -->
    <view :class="renwu_show?'renwu renwu_donghua':'renwu'">
      <view class="renwu-list">
        <view class="top"></view>
        <view @click="show_renwu" class="top-icon-x"></view>
        <view class="renwu-item" v-for="(item,index) in 4">
          <view class="item-info">
            <view class="item-img">
              <image src="https://wechat-pictures-1301970825.file.myqcloud.com/yangji/时间.png"></image>
            </view>
            <view class="item-title">今日签到</view>
          </view>
          <view class="item-set">

            <view class="item-text">已完成
              <text>3/5</text>
            </view>
            <view class="item-button">进入</view>
          </view>
        </view>
      </view>
    </view>
    <!-- 食物 -->
    <view v-if="donghua.jishi" class="shiwu"></view>
    <!-- 铲子 -->
    <view v-if="donghua.chanshi" class="chanshi">
      <image src="https://wechat-pictures-1301970825.file.myqcloud.com/yangji/chanzi.png"></image>
    </view>
    <!-- 好友列表 -->
    <view v-if="donghua.user_list" :class="donghua.user_list?'user-list user-list-donghua':'user-list' ">
      <view class="user-item" v-for="(item,index) in user_list.friend_list" @click="to_userjichang(index)">
        <view class="user-img">
          <view class="chanzi-icon">
            <image src="https://wechat-pictures-1301970825.file.myqcloud.com/yangji/chanzi.png"></image>
          </view>

          <image :src="item.avatar"></image>
        </view>
        <view class="user-name">{{ item.nick_name }}</view>
      </view>
    </view>
    <view v-if="donghua.user_list" @click="donghua.user_list=!donghua.user_list" class="zhezhao"></view>
    <view v-if="renwu_show" @click="show_renwu(0)" class="zhezhao"></view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      moutou: false,
      count: 0,
      left: '50%',
      message_count: 1,
      percent: 0,
      renwu_show: false,
      ji_info: {}, //鸡的信息
      message_list: [], //消息
      message_index: 0,
      donghua: {
        jishi: false,
        fanpen: false,
        chanshi: false,
        baba: false,
        message: false,
        user_list: false,
        message_list: false
      },
      t_message: "",
      user_list: [],
      user_info: "",
      is_ji_gif: true
    }
  },
  onShareAppMessage() {

  },
  onLoad(e) {
    var _this = this;
    _this.user_info = JSON.parse(e.user_info)
  },
  onShow() {
    this.message();
    this.get_ji(); //获取鸡的信息
  },
  methods: {
    //弹出任务
    show_renwu() {
      this.renwu_show = !this.renwu_show
    },
    //消息弹出
    message() {
      var _this = this;
      _this.$api.doRequest("get", "api/egg_broadcast_list", {}, false).then(res => {
        _this.message_list = res.data.data;
        var count = res.data.data;
        _this.donghua.message_list = true
        setInterval(function () {
          _this.message_index = _this.message_index + 1;
          if (count.length <= _this.message_index) {
            _this.message_index = 0
          }
        }, 2900)
      })
    },
    //摸摸鸡头
    set_motou() {
      var ji_info = this.ji_info;
      var _this = this;
      _this.tanchu_message(ji_info.huashu_gonglue.trjcmj[0].content);
    },
    randomNum(minNum, maxNum) {
      switch (arguments.length) {
        case 1:
          return parseInt(Math.random() * minNum + 1, 10);
          break;
        case 2:
          return parseInt(Math.random() * (maxNum - minNum + 1) + minNum, 10);
          break;
        default:
          return 0;
          break;
      }
    },
    //获取话术
    get_message() {

    },
    //领取鸡蛋
    jiwu() {
      var _this = this;
      _this.tanchu_message(_this.ji_info.huashu_gonglue.trjcmd[0].content)


    },
    //获取鸡的状态，心情，当前行为,为食
    get_ji() {
      var _this = this;
      _this.$api.doRequest("post", "api/chicken_friend_info", {friend_user_id: _this.user_info.friend_user_id}, false).then(res => {
        _this.ji_info = res.data.data;
        _this.percent = res.data.data.chicken_info.fodder / 500 * 100;
        _this.is_ji_gif = false
      })
    },
    //获取鸡蛋,未领取鸡蛋，已领取鸡蛋，生产中的鸡蛋
    get_jidan() {

    },
    //清理鸡粑粑
    del_ji_baba() {
      var _this = this;
      if (_this.donghua.chanshi) {
        uni.showToast({
          title: "操作过于频繁，请稍后再试！",
          icon: "none"
        })
        return false
      }
      _this.donghua.chanshi = true;
      _this.donghua.baba = true;
      _this.tanchu_message(_this.ji_info.huashu_gonglue.trjcqljf[0].content)
      var data = {
        friend_user_id: _this.user_info.friend_user_id
      }
      _this.$api.doRequest("post", 'api/help_other_get_fodder2', data, false).then(res => {
        _this.get_ji()
      })
    },
    //给鸡喂食
    add_jishi() {
      var _this = this;
      _this.$api.doRequest("get", "api/feed_the_chicken", {}, false).then(res => {
        _this.get_ji()
      })
    },
    //换鸡蛋
    huanjidan() {
      uni.redirectTo({
        url: "/yangji/duihuan/index"
      })
    },
    //喂饲料动画
    weisiliao() {
      var _this = this;
      var ji_info = this.ji_info;
      if (ji_info.jinshi_info.is_over == 0) {
        return false;
      } else {
        if (ji_info.chicken_info.fodder >= 60) {
          _this.tanchu_message(_this.ji_info.huashu_gonglue.zjjcwssldyls[0].content)
        } else {
          _this.tanchu_message(_this.ji_info.huashu_gonglue.zjjcwsslxyls[0].content)
        }

      }
      _this.donghua.jishi = true;
      setTimeout(function () {
        _this.donghua.jishi = false;
        _this.donghua.fanpen = true;
        setTimeout(function () {
          _this.ji_info.jinshi_info.is_over = false;
          _this.add_jishi(); //执行接口
        }, 300)
      }, 1000)
    },
    //小鸡说话
    tanchu_message(message) {
      var _this = this;
      if (!_this.donghua.message) {
        _this.donghua.message = true;
        _this.t_message = message;
        setTimeout(function () {
          _this.donghua.message = false;
        }, 3000)
      }
    },
    //一分钟同步一下
    tongbu_ji() {
      var _this = this;
      setInterval(function () {
        _this.ji_info();
      }, 60000)
    },
    // 获取好友列表
    get_user_list() {
      uni.redirectTo({
        url: "../index/index"
      })
    },
    //去他人鸡场
    to_userjichang(index) {
      var item = this.user_list.friend_list[index];
      var userinfo = JSON.stringify(item);
      uni.navigateTo({
        url: "../userjichang/index?user_info=" + userinfo
      })
    }
  },
}
</script>

<style>
@import "/yangji/static/yangji.css";

.haoyou {
  position: fixed;
  bottom: 108upx;
  left: 44upx;
}

.lingqu {
  background: #DCDFE6 !important;
}
</style>
